<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jspf/include.jspf" %>
<select id="localeSelect" onchange="changeLocale();">
    <option value=""><fmt:message key="language.change"/></option>
    <option value="en"><fmt:message key="language.en"/></option>
    <option value="ru"><fmt:message key="language.ru"/></option>
    <option value="ua"><fmt:message key="language.ua"/></option>
</select>

<script type="text/javascript">
    // <![CDATA[

    function changeLocale() {
        var locale = $('localeSelect').value;
        if (locale.length > 0) {
            var loc = new String(window.location);
            var questionPos = loc.indexOf('?');
            if (questionPos == -1) {
                window.location = "?locale=" + locale;
            } else {
                var i = loc.indexOf('locale');
                if (i != -1) {
                    var lastPart = loc.substring(i + 9);
                    var ampPos = lastPart.indexOf('&');
                    if (ampPos != -1) {
                        lastPart = lastPart.substring(ampPos);
                    }
                    window.location = loc.substring(0, i) + 'locale=' + locale + lastPart;
                } else {
                    window.location = loc + '&locale=' + locale;
                }
            }
        }
    }

    $('localeSelect').value = '${locale}';

    // ]]>
</script>
